#include "examples.h"

void runglLogisticR(){
	int m,n,k,state,i;
	double *A, *xorin, *noise, *y, rho, q;
	double *gWeights;
	int ind[]={0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000};
	double sWeight[] = {1,1};
	OPTS opt;
	double c1,c2;
	stopWatch sw;
	FUNVAL result1,result2,result3;
	m=n=1000;
	k=10;
	q = 2.0;
	A= (double *) malloc( sizeof(double) * m* n);
	xorin = (double *) malloc(sizeof(double) * n);
	noise = (double *) malloc(sizeof(double) * m);
	y = (double *) malloc(sizeof(double) * m);



	state = 2344;
	acml_randseed(state);
	acml_randn(A,m*n,0.0,1.0);

	state = 13255;
	acml_randseed(state);
	acml_randn(xorin,n,0.0,1.0);

	state = 333;
	acml_randseed(state);
	acml_randn(noise,m,0.0,1.0);
	dcopy(m,noise,1,y,1);

	dgemv('N',m,n,1.0,A,m,xorin,1,0.01l,y,1);
	dcopy(m,oneVector,1,y,1);
	dscal(m/2,-1.0,&y[m/2],1);


	fprintM("J:\\Thesis\\temp\\c\\A.glLog.matrix",A,m,n);
	fprintM("J:\\Thesis\\temp\\c\\y.glLog.matrix",y,m,1);
	rho = 0.1l;
	memset(A,0,m*n*sizeof(double));
	memset(y,0,m*sizeof(double));
	fscanM("J:\\Thesis\\temp\\c\\A.glLog.matrix",A,m,n);
	fscanM("J:\\Thesis\\temp\\c\\y.glLog.matrix",y,m,1);

	c2 = 0.8;

	initOPTS(&opt,m,n,0);
	opt.sWeight[0] = 1.0;
	opt.sWeight[1] = 1.0;
	gWeights = (double *) malloc( sizeof(double) * k);
	for(i=0; i<k ; i++ )
		gWeights[i] = 1.0;
	setOPTgWeights(&opt,gWeights);

	//dcopy(k,oneVector,1,gWeights,1);
	//setOPTgWeights(&opt,gWeights);
	//setOPTsWeight(&opt,sWeight);
	//setOPTq(&opt,q);
	//setOPTind(&opt,ind,k+1);

	setOPTq(&opt,q);
	setOPTind(&opt,ind,k+1);
	opt.init = 2;
	opt.maxIter = 100;
	opt.nFlag = 0;
	opt.tFlag = 5;
	opt.rFlag = 1;

	opt.mFlag=0;
	opt.lFlag =0;
	startTimer(&sw);
	result1 = glLogisticR(A,y,c2,opt);
	stopTimer(&sw);
	printf("Time taken = %lf\n",getElapsedTime(&sw));

	startTimer(&sw);
	opt.mFlag = 1;
	opt.lFlag = 0;
	result2 = glLogisticR(A,y,c2,opt);
	stopTimer(&sw);
	printf("Time taken = %lf\n",getElapsedTime(&sw));

	startTimer(&sw);
	opt.mFlag = 1;
	opt.lFlag = 1;
	result3 = glLogisticR(A,y,c2,opt);
	stopTimer(&sw);
	printf("Time taken = %lf\n",getElapsedTime(&sw));


	fprintM("J:\\Thesis\\temp\\c\\glLog.x1",result1.x,n,1);
	fprintM("J:\\Thesis\\temp\\c\\glLog.fVal1",result1.funVal,opt.maxIter,1);
	fprintM("J:\\Thesis\\temp\\c\\glLog.L1",result1.ValueL,opt.maxIter,1);
	free(result1.x);
	free(result1.funVal);
	free(result1.ValueL);

	fprintM("J:\\Thesis\\temp\\c\\glLog.x2",result2.x,n,1);
	fprintM("J:\\Thesis\\temp\\c\\glLog.fVal2",result2.funVal,opt.maxIter,1);
	fprintM("J:\\Thesis\\temp\\c\\glLog.L2",result2.ValueL,opt.maxIter,1);
	free(result2.x);
	free(result2.funVal);
	free(result2.ValueL);

	fprintM("J:\\Thesis\\temp\\c\\glLog.x3",result3.x,n,1);
	fprintM("J:\\Thesis\\temp\\c\\glLog.fVal3",result3.funVal,opt.maxIter,1);
	fprintM("J:\\Thesis\\temp\\c\\glLog.L3",result3.ValueL,opt.maxIter,1);
	free(result3.x);
	free(result3.funVal);
	free(result3.ValueL);

}